<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2023/12/14
 * Time: 15:52
 */

namespace app\api\model;

class OrderInfo extends Base
{
    /**
     * 插入订单详情
     * @param $data
     * @return array|false|\think\Collection|\think\model\Collection
     * @throws \Exception
     */
    static function saveOrderInfo($data = []){
        return self::insertAll($data);
    }

    /**
     * 关联系列查询
     * @param $where
     * @param $field
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function selectJoinXl($where = [], $field = '*'){
        $data = self::where($where)
            ->join('up_xl', 'device_id = oi_xl', 'LEFT')
            ->field($field)
            ->select()
            ->toArray();
        return $data;
    }

    /**
     * 关联查询
     * @param $where
     * @param $field
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function selectJoin($where = [], $field = '*'){
        $data = self::where($where)
            ->join('up_xl x1', 'x1.device_id = oi_xl', 'LEFT')
            ->join('up_xl x2', 'x2.device_id = oi_xh', 'LEFT')
            ->join('up_gz', 'gz_id = oi_gz', 'LEFT')
            ->field($field)
            ->select()
            ->toArray();
        return $data;
    }
}